package com.wawei.seeds.services;

import android.content.Context;
import android.os.Handler;

import com.wawei.seeds.adapter.ChampionBiddingFragmentAdapter;
import com.wawei.seeds.champion.ChampionBiddingTabFragment;
import com.wawei.seeds.utils.RetrofitNetworkService;

import java.util.ArrayList;
import java.util.List;

import retrofit.RestAdapter;

/**
 * Created by parker on 15/6/7.
 */
public class BiddingServiceHandler {
    private Context context;

    public BiddingServiceHandler(Context context) {
        this.context = context;
    }

    public void retriveBidding(RestAdapter restAdapter, int count,
                          final Handler handler, final Integer handlerTag){
        //TODO: get real bidding data from remote server
        //Mock

        List<ChampionBiddingFragmentAdapter.ChampionBiddingItem> items = new ArrayList<>();
        ChampionBiddingFragmentAdapter.ChampionBiddingItem item;
        if(handlerTag.intValue() == ChampionBiddingTabFragment.INIT_BIDDING_DATA){
            for(int i=0;i<20;i++) {
                item = new ChampionBiddingFragmentAdapter.ChampionBiddingItem();
                item.biddingTitle = new String("APP" + i + "原型设计");
                item.biddingAmount = String.valueOf(1000 + i) + " RMB";
                item.biddingPublishTime = new String("15-06-03 13:20:34_" + i);
                item.biddingStatus = "Applicants: 10000";

                items.add(item);
            }//End of mock
        }
        else if(handlerTag.intValue() == ChampionBiddingTabFragment.LOAD_OLD_BIDDING_DATA){
            for(int i=0;i<10;i++) {
                item = new ChampionBiddingFragmentAdapter.ChampionBiddingItem();
                item.biddingTitle = new String("APP" + Math.rint(10 * Math.random()) + "原型设计");
                item.biddingAmount = String.valueOf(1000 * Math.rint(10 * Math.random())) + " RMB";
                item.biddingPublishTime = new String("15-06-03 13:20:34_" + Math.rint(100 * Math.random()));
                item.biddingStatus = "Applicants: " + Math.rint(10000 * Math.random());

                items.add(item);
            }//End of mock

        }
        else if(handlerTag.intValue() == ChampionBiddingTabFragment.LOAD_NEW_BIDDING_DATA){
            for(int i=0;i<10;i++) {
                item = new ChampionBiddingFragmentAdapter.ChampionBiddingItem();
                item.biddingTitle = new String("APP" + Math.rint(10 * Math.random()) + "原型设计");
                item.biddingAmount = String.valueOf(1000 * Math.rint(10 * Math.random())) + " RMB";
                item.biddingPublishTime = new String("15-06-03 13:20:34_" + Math.rint(100 * Math.random()));
                item.biddingStatus = "Applicants: " + Math.rint(10000 * Math.random());

                items.add(item);
            }//End of mock
        }

        RetrofitNetworkService.handleSuccess(handler, handlerTag, items.toArray());
    }
}
